<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 韩金龙
  Date: 2021/12/13
  Time: 16:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.9.1.min.js"></script>
</head>
<body>
<form action="list.do" method="post">
    <input type="hidden" name="pageNum">
    商品名称:<input type="text" name="sname" value="${map.sname}">
    商品价格:<input type="text" name="priceMin" value="${map.priceMin}"> - <input type="text" name="priceMax" value="${map.priceMax}">
    <input type="submit" value="搜索">
</form>
<table>
    <tr>
        <td><input type="checkbox"></td>
        <td>编号</td>
        <td>名称</td>
        <td>品牌</td>
        <td>规格</td>
        <td>价格</td>
        <td>上架时间</td>
    </tr>
    <c:forEach items="${pageInfo.list}" var="li">
        <tr>
            <td>
                <input type="checkbox" class="xz" value="${li.sid}">
            </td>
            <td>${li.sid}</td>
            <td>${li.sname}</td>
            <td>${li.pname}</td>
            <td>${li.ssty}</td>
            <td>${li.price}</td>
            <td>${li.time}</td>
        </tr>
    </c:forEach>
    <tr>
       <td colspan="20">
           <button onclick="fy(1)">首页</button>
           <button onclick="fy(${pageInfo.isFirstPage?1:pageInfo.prePage})">上页</button>
           <button onclick="fy(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">下页</button>
           <button onclick="fy(${pageInfo.pages})">尾页</button>
           第${pageInfo.pageNum}/${pageInfo.pages}页
           <button onclick="ps()">批删</button>
           <button onclick="addTo()">添加</button>
       </td>
    </tr>
</table>
</body>
<script>
    function fy(pageNum) {
        $("[name='pageNum']").val(pageNum)
        $("form").submit()
    }
    function ps() {
        var sid = 0
        $(".xz:checked").each(function () {
            sid+=","+$(this).val()
        })
        $.ajax({
            url:"dels.do",
            type:"post",
            data:{"sid":sid},
            dataType:"json",
            success:function(obj) {
                console.log(obj)
                if (obj>0){
                    alert("删除成功!!")
                    location="list.do"
                }
            }
        })
    }
    function addTo() {
        location="addTo.do"
    }
</script>
</html>
